The most basic way of returning outputs from a Scirpt Unit is to just use the return
statement.
For example, you may extract data from your JSON structure and turn it into a list of Groovy maps, and then return the entire list.
def result = []
def http = new HTTPBuilder('http://twitter.com/statuses/')
http.get(path: 'user_timeline.json', query: [id:'httpbuilder', count:5] ) { resp, son ->
def entry = [""created"": it.created_at, ""text"": it.text]
result.add(entry)
}
return result
Another possibility, if your data is ""flat"", is returning a series of related lists, each one including a piece of data.
#output String[] creationTimes
#output String[] texts
def creationTimes = []
def texts = []
def http = new HTTPBuilder('http://twitter.com/statuses/')
http.get(path: 'user_timeline.json', query: [id:'httpbuilder', count:5] ) { resp, son ->
creationTimes.add(it.created_at)
texts.add(it.text)
}
return [""creationTimes"": creationTimes, ""texts"", texts]
This will cause your Script Unit to output two parameters that can be conveniently coupled to two attributes, for example of a Create Unit for storing data on database.
For more information about the #output
syntax, please see the wiki article introducing the Script Unit (section Declaring typed inputs and outputs).